package route

import (
	"time"

	"gitee.com/jiebaiyou/formflow/api/controller"
	"gitee.com/jiebaiyou/formflow/bootstrap"
	"gitee.com/jiebaiyou/formflow/pkg/storage/redis"
	"gitee.com/jiebaiyou/formflow/pkg/storage/sqlite"
	"gitee.com/jiebaiyou/formflow/repository"
	"gitee.com/jiebaiyou/formflow/service"
	"github.com/gin-gonic/gin"
)

// NewSignupRouter 创建并注册用户注册路由
func NewSignupRouter(env *bootstrap.Config, timeout time.Duration, db sqlite.DB, cache redis.Database, group *gin.RouterGroup) {
	// 初始化用户仓储
	ur := repository.NewUserRepository(db, cache)
	// 初始化注册服务
	ss := service.NewSignupService(ur, timeout)
	// 初始化注册控制器
	sc := controller.SignupController{
		SignupService: ss,
		Env:           env,
	}

	// 注册用户路由
	group.POST("/signup", sc.Signup)
}
